import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:load_switch/load_switch.dart';
import 'package:sgy_flutter/gen/assets.gen.dart';
import 'package:sgy_flutter/page/device_setting/view.dart';
import 'package:sgy_flutter/page/power_offset/view.dart';
import 'package:sgy_flutter/page/question/logic.dart';
import 'package:sgy_flutter/widget/app_bar_x.dart';
import 'package:sgy_flutter/widget/shadow_container.dart';
import 'package:sgy_flutter/widget/switch_x.dart';

import 'logic.dart';

class OtherSettingsPage extends StatefulWidget {
  const OtherSettingsPage({Key? key}) : super(key: key);

  @override
  State<OtherSettingsPage> createState() => _OtherSettingsPageState();
}

class _OtherSettingsPageState extends State<OtherSettingsPage> {
  final logic = Get.put(OtherSettingsLogic());

  @override
  Widget build(BuildContext context) {
    double height = 70;

    return Scaffold(
      appBar: AppBarX(
        title: Text("其他设置".tr),
      ),
      backgroundColor: Colors.white,
      body: Obx(
        () => Column(
          children: [
            Visibility(
              visible: logic.reverseChain2ZeroVisible.value,
              child: ShadowContainer(
                margin: EdgeInsets.only(left: 16, right: 16, top: 16),
                padding: EdgeInsets.symmetric(horizontal: 16),
                borderRadius: BorderRadius.circular(8),
                height: height,
                enable: logic.ready.value,

                child: Row(
                  children: [
                    Assets.image.icDlgl.image(width: 60, height: 26),
                    Text(
                      "倒链归零".tr,
                      style: TextStyle(fontSize: 17, color: logic.ready.isTrue
                          ? Colors.black
                          : Colors.grey),
                    ).marginOnly(left: 8),
                    Spacer(),
                    SwitchX(
                      future: ()=>logic.toggleReverseChain2ZeroOn(),
                      value: logic.reverseChain2ZeroOn.value,
                      enable: logic.ready.value,
                      onTap: (v){
                        // logic.toggleReverseChain2ZeroOn();
                      },
                    ),
                  ],
                ),
              ),
            ),
            Visibility(
              visible: logic.transportModeVisible.value,
              child: ShadowContainer(
                margin: EdgeInsets.only(left: 16, right: 16, top: 16),
                padding: EdgeInsets.symmetric(horizontal: 16),
                borderRadius: BorderRadius.circular(8),
                height: height,
                enable: logic.ready.value,

                child: Row(
                  children: [
                    Assets.image.icYsml.image(width: 60),
                    Text(
                      "运输模式".tr,
                      style: TextStyle(fontSize: 17, color: logic.ready.isTrue
                          ? Colors.black
                          : Colors.grey),
                    ).marginOnly(left: 8, right: 6),
                    // Assets.image.iconWarningBlack.image(width: 18),
                    Spacer(),
                    SwitchX(
                      future: ()=>logic.openTransportMode(),
                      value: logic.transportModeOn.value,
                      enable: logic.ready.value,
                      onTap: (v){
                        // logic.openTransportMode();
                      },
                    )
                  ],
                ),
              ),
            ),
            Visibility(visible: logic.deviceCheckVisible.value,child: ShadowContainer(
              margin: EdgeInsets.only(left: 16, right: 16, top: 16),
              padding: EdgeInsets.symmetric(horizontal: 16),
              borderRadius: BorderRadius.circular(8),
              height: height,
              enable: logic.ready.value,
              onTap: logic.ready.isFalse ? null : () {
                final osLogic = QuestionLogic();
                osLogic.showDetectionDialog();
              },
              child: Row(
                children: [
                  Assets.image.icSelfTest.image(width: 60),
                  Text(
                    "设备自检".tr,
                    style: TextStyle(fontSize: 17, color: logic.ready.isTrue
                        ? Colors.black
                        : Colors.grey),
                  ).marginOnly(left: 8),
                  Spacer(),
                  Icon(
                    Icons.arrow_forward_ios,
                    size: 16,
                    color: Colors.grey,
                  ),
                ],
              ),
            )),
            ShadowContainer(
              margin: EdgeInsets.only(left: 16, right: 16, top: 16),
              padding: EdgeInsets.symmetric(horizontal: 16),
              borderRadius: BorderRadius.circular(8),
              height: height,
              enable: logic.ready.value,
              onTap: logic.ready.isFalse ? null :  () {
                Get.to(()=> PowerOffsetPage());
              },
              child: Row(
                children: [
                  Assets.image.icPowerOffsetAdjust.image(width: 60),
                  Text(
                    "功率偏移调整".tr,
                    style: TextStyle(fontSize: 17, color: logic.ready.isTrue
                          ? Colors.black
                          : Colors.grey),
                  ).marginOnly(left: 8),
                  Spacer(),
                  Icon(
                    Icons.arrow_forward_ios,
                    size: 16,
                    color: Colors.grey,
                  ),
                ],
              ),
            ),
            Visibility(
              visible: logic.deviceSettingVisible.value,
              child: ShadowContainer(
                margin: EdgeInsets.only(left: 16, right: 16, top: 16),
                padding: EdgeInsets.symmetric(horizontal: 16),
                borderRadius: BorderRadius.circular(8),
                height: height,
                enable: logic.ready.value,
                onTap: logic.ready.isFalse ? null : () {
                  Get.to(()=>DeviceSettingPage());
                },
                child: Row(
                  children: [
                    Assets.image.icSetting.image(width: 60, height: 26),
                    Text(
                      "踏频检测设置".tr,
                      style: TextStyle(fontSize: 17, color: logic.ready.isTrue
                          ? Colors.black
                          : Colors.grey),
                    ).marginOnly(left: 8),
                    Spacer(),
                    Icon(
                      Icons.arrow_forward_ios,
                      size: 16,
                      color: Colors.grey,
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  @override
  void dispose() {
    Get.delete<OtherSettingsLogic>();
    super.dispose();
  }
}
